﻿using UnityEngine;
using System.Collections;

public class SingleMyTurnState : State
{
    private GamePlayScene _playScene = null;
    private Character _myChararcter = null;

    public override void EnterState()
    {
        _playScene = GameCommon.GetPlayScene();
        _myChararcter = _playScene._characterMgr.GetCharacter(0);
    }

    public override void UpdateState(float fDT)
    {
        MoveUpdate();
    }

    public override void EndState()
    {
    }

	public void Move( GameObject obj )
	{
		string name = obj.name;

		if( name == "LeftBtn" || name == "RightBtn" )
			_myChararcter.SetAnimState(Character.AnimationState.idle);

		if (name == "LeftBtn")
		{
			_playScene._messageViewCtrl.SingleMoveCharacter(_myChararcter, MoveDirection.left, Time.deltaTime);
			_myChararcter.SetAnimState(Character.AnimationState.run);
		}
		else if (name == "RightBtn")
		{
			_playScene._messageViewCtrl.SingleMoveCharacter(_myChararcter, MoveDirection.right, Time.deltaTime);
			_myChararcter.SetAnimState(Character.AnimationState.run);
		}
		else if (name == "FireBtn")
		{
			_playScene._messageViewCtrl.SingleFireGun(_myChararcter);
		}
	}
	
    public void MoveUpdate()
    {
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
            _myChararcter.SetAnimState(Character.AnimationState.idle);

        if (Input.GetKey(KeyCode.A))
        {
            _playScene._messageViewCtrl.SingleMoveCharacter(_myChararcter, MoveDirection.left, Time.deltaTime);
            _myChararcter.SetAnimState(Character.AnimationState.run);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            _playScene._messageViewCtrl.SingleMoveCharacter(_myChararcter, MoveDirection.right, Time.deltaTime);
            _myChararcter.SetAnimState(Character.AnimationState.run);
        }
        else if (Input.GetKey(KeyCode.W))
        {
            _playScene._messageViewCtrl.SingleRotateGunBarrel(_myChararcter, 1, Time.deltaTime);
        }
        else if (Input.GetKey(KeyCode.S))
        {
            _playScene._messageViewCtrl.SingleRotateGunBarrel(_myChararcter, -1, Time.deltaTime);
        }

        else if (Input.GetKey(KeyCode.Space))
        {
            _playScene._messageViewCtrl.SingleFireGun(_myChararcter);
        }
    }
}
